Functions with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their
position.
def modify(x1, y1, z1, x2, y2, z2) # Noncompliant
# ...
end
The solution can be to:
- Split the function into smaller ones
# Each function does a part of what the original distance function was doing, so confusion risks are lower
def move(x, y, z)
# ...
end
def resize(width, height, depth)
# ...
end
- Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain
Point = Struct.new(:x, :y, :z) # In geometry, Point is a logical structure to group data
def modify(p1, p2)
# ...
end
This rule raises an issue when a function has more parameters than the provided threshold.